package com.zjhn.ds.controller.pc;

import com.alibaba.fastjson.JSON;
import com.zjhn.ds.common.BizResult;
import com.zjhn.ds.common.PageBean;
import com.zjhn.ds.common.PageResult;
import com.zjhn.ds.domain.dto.pc.EquipmentTypeDto;
import com.zjhn.ds.domain.dto.pc.ModelDto;
import com.zjhn.ds.param.AddUpdateModelParam;
import com.zjhn.ds.param.AddUpdateTypeParam;
import com.zjhn.ds.param.ModelPageParam;
import com.zjhn.ds.service.ModelTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @BelongsProject: ds_jlw
 * @BelongsPackage: com.zjhn.ds.controller.pc
 * @Author: sxt
 * @CreateTime: 2023-09-12  17:25
 * @Description:
 * @Version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/jlw/modelType")
@Api(tags = "pc端设备类别和模型接口")
public class ModelTypeController {

    @Resource
    private ModelTypeService modelTypeService;

    @ApiOperation("新增/编辑设备类别")
    @PostMapping("/addUpdateType")
    public BizResult<?> addUpdateType(@RequestBody @Valid AddUpdateTypeParam param) {
        log.info("====[INFO]=========ModelTypeController====addUpdateType param:{}", JSON.toJSONString(param));
        return modelTypeService.addUpdateType(param);
    }

    @ApiOperation("删除设备类别")
    @GetMapping("/removeType")
    public BizResult<?> removeType(@RequestParam("type_id") String typeId) {
        log.info("====[INFO]=========ModelTypeController====removeType typeId:{}", typeId);
        return modelTypeService.removeType(typeId);
    }

    @ApiOperation("分页查询设备类别")
    @PostMapping("/typePage")
    public BizResult<PageResult<EquipmentTypeDto>> typePage(@RequestBody @Valid PageBean param) {
        log.info("====[INFO]=========ModelTypeController====typePage param:{}", JSON.toJSONString(param));
        return modelTypeService.typePage(param);
    }

    @ApiOperation("新增/编辑模型")
    @PostMapping("/addUpdateModel")
    public BizResult<?> addUpdateModel(@RequestBody @Valid AddUpdateModelParam param) {
        log.info("====[INFO]=========ModelTypeController====addUpdateModel param:{}", JSON.toJSONString(param));
        return modelTypeService.addUpdateModel(param);
    }

    @ApiOperation("删除模型")
    @GetMapping("/removeModel")
    public BizResult<?> removeModel(@RequestParam("model_id") String modelId) {
        log.info("====[INFO]=========ModelTypeController====removeModel modelId:{}", modelId);
        return modelTypeService.removeModel(modelId);
    }

    @ApiOperation("按条件分页查询模型")
    @PostMapping("/modelPage")
    public BizResult<PageResult<ModelDto>> modelPage(@RequestBody @Valid ModelPageParam param) {
        log.info("====[INFO]=========ModelTypeController====modelPage param:{}", JSON.toJSONString(param));
        return modelTypeService.modelPage(param);
    }
}
